/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JP_Busqueda.java
 *
 * Created on 11/05/2009, 04:16:45 PM
 */

package helper;
import com.jidesoft.hints.ListDataIntelliHints;
import java.util.ArrayList;
import java.util.List;
/**
 *
 * @author Frank Gabriel Rodríguez Lee
 */
public class JP_Busqueda extends javax.swing.JPanel {

    /** Creates new form JP_Busqueda */
    public JP_Busqueda() {
        inicializaComponentes();
    }

    public void inicializaComponentes(){
        initComponents();
        listaDatos = new ArrayList(1);
        intelliHints = new ListDataIntelliHints( this.txtBus, listaDatos );
        bg.add(rbCodigo);
        bg.add(rbNombre);
        rbCodigo.setSelected(true);        
        intelliHints.setAutoPopup(false);
    }

    public List getListaDatos() {
        return listaDatos;
    }

    public void setListaDatos(List listaDatos) {
        this.listaDatos.addAll(listaDatos);
    }

    
    

    public JP_Modelo getPanel_modelo() {
        return panel_modelo;
    }

    public void setPanel_modelo(JP_Modelo panel_modelo) {
        this.panel_modelo = panel_modelo;
    }

    public String getCodigo() {
        return codigo;
    }

    public void setCodigo(String codigo) {
        this.codigo = codigo;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bg = new javax.swing.ButtonGroup();
        btnConsultar = new javax.swing.JButton();
        txtBus = new javax.swing.JTextField();
        rbCodigo = new javax.swing.JRadioButton();
        rbNombre = new javax.swing.JRadioButton();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(controlaccionescomercial.ControlAccionesComercialApp.class).getContext().getResourceMap(JP_Busqueda.class);
        setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("Form.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("Form.border.titleFont"))); // NOI18N
        setName("Form"); // NOI18N

        btnConsultar.setFont(resourceMap.getFont("btnConsultar.font")); // NOI18N
        btnConsultar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/fife/plaf/Office2003/find.gif"))); // NOI18N
        btnConsultar.setText(resourceMap.getString("btnConsultar.text")); // NOI18N
        btnConsultar.setName("btnConsultar"); // NOI18N
        btnConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConsultarActionPerformed(evt);
            }
        });

        txtBus.setName("txtBus"); // NOI18N

        rbCodigo.setFont(resourceMap.getFont("rbCodigo.font")); // NOI18N
        rbCodigo.setText(resourceMap.getString("rbCodigo.text")); // NOI18N
        rbCodigo.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        rbCodigo.setMargin(new java.awt.Insets(0, 0, 0, 0));
        rbCodigo.setName("rbCodigo"); // NOI18N
        rbCodigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbCodigoActionPerformed(evt);
            }
        });

        rbNombre.setFont(resourceMap.getFont("rbNombre.font")); // NOI18N
        rbNombre.setText(resourceMap.getString("rbNombre.text")); // NOI18N
        rbNombre.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        rbNombre.setMargin(new java.awt.Insets(0, 0, 0, 0));
        rbNombre.setName("rbNombre"); // NOI18N
        rbNombre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbNombreActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(txtBus, javax.swing.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnConsultar))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(rbCodigo)
                        .addGap(18, 18, 18)
                        .addComponent(rbNombre)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rbCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rbNombre))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtBus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnConsultar)))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConsultarActionPerformed
        if( this.rbCodigo.isSelected() ){
            this.codigo = this.txtBus.getText().trim();
        }else if( this.rbNombre.isSelected() ){
        }
        panel_modelo.consulta();    //Ejecutamos la consulta definida en el formulario
    }//GEN-LAST:event_btnConsultarActionPerformed

    private void rbCodigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbCodigoActionPerformed
        intelliHints.setAutoPopup(false);
    }//GEN-LAST:event_rbCodigoActionPerformed

    private void rbNombreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbNombreActionPerformed
        intelliHints.setAutoPopup(true);
    }//GEN-LAST:event_rbNombreActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup bg;
    private javax.swing.JButton btnConsultar;
    private javax.swing.JRadioButton rbCodigo;
    private javax.swing.JRadioButton rbNombre;
    private javax.swing.JTextField txtBus;
    // End of variables declaration//GEN-END:variables

    private JP_Modelo panel_modelo;
    private String codigo;

    private List listaDatos;
    private ListDataIntelliHints intelliHints;
}
